package yja.gzw.app.activity

import android.widget.Toast
import androidx.lifecycle.Observer
import yja.gzw.app.R
import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityWangjimmBinding
import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel
import yja.gzw.app.window.Chicun

class WangjimmActivity :BaseActivity<Mainviewmodel, ActivityWangjimmBinding>(R.layout.activity_wangjimm){
    val chicun= Chicun()

    override fun initView() {

        val biaotiti=intent.getStringExtra("biaoti")

        if(biaotiti==""||biaotiti==null){
            binding.biaoti.text="忘记密码"
        }else{

            binding.biaoti.text=biaotiti
        }




        binding.fanhui.setOnClickListener {
            finish()
        }


        chicun.chicunwai(binding.fanhui, 20, 60,0,0)
        chicun.chicunwai(binding.biaoti, 0, 60, 0, 0)
        chicun.chicunwai(binding.tubiao,0,100,0,0)
        chicun.chicun(binding.tubiao,110,130)
        chicun.chicunwai(binding.name, 20,20,20,0)
        chicun.chicun(binding.name,UserData.kuan,50)
        chicun.chicunwai(binding.sfz, 20,20,20,0)
        chicun.chicun(binding.sfz,UserData.kuan,50)
        chicun.chicunwai(binding.onemima, 20,20,20,0)
        chicun.chicun(binding.onemima,UserData.kuan,50)
        chicun.chicunwai(binding.twomima, 20,20,20,0)
        chicun.chicun(binding.twomima,UserData.kuan,50)
        chicun.chicun(binding.denglu,280,50)
        binding.denglu.setOnClickListener {
            val zhanghao=binding.name.text.toString()
            val sfz=binding.sfz.text.toString()
            val mima1=binding.onemima.text.toString()
            val mima2=binding.twomima.text.toString()
                viewmodel.onchongzhimimawang(mapOf("username" to zhanghao,"newpassword" to mima1,"confirmpassword" to mima2,"id_card" to sfz))

        }





    }

    override fun dataObservese() {
        viewmodel.onchongzhimima.observe(this, Observer {
            if(it.code==1){
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
                finish()

            }else{
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
            }


        })


    }
}